package com.aibili.service;

import java.util.List;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Propagation;
import org.springframework.transaction.annotation.Transactional;

import com.aibili.pojo.UserDevice;

@Service("userDeviceService")
@Transactional(readOnly = true, propagation = Propagation.SUPPORTS)
public class UserDeviceService extends BaseService {

	/**
	 * 
	 * @Description 新增设备信息
	 * @param device
	 */
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public void add(UserDevice device) {
		dataDao.addObject(device);
	}

	/**
	 * 
	 * @Description 修改设备信息
	 * @param device
	 */
	@Transactional(readOnly = false, propagation = Propagation.REQUIRED)
	public void update(UserDevice device) {
		dataDao.updateObject(device);
	}

	/**
	 * 
	 * @Description 通过设备id查找设备信息
	 * @param clientid
	 * @return
	 */
	public UserDevice getByClientid(String client_id, int type) {
		String hql = " from UserDevice where client_id = :client_id and type = :type ";
		UserDevice device = null;
		device = (UserDevice) dataDao.getFirstObjectViaParam(hql, new String[] { "client_id", "type" }, client_id,
				type);
		return device;
	}

	/**
	 * 
	 * @Description 通过 user_id 查找设备信息
	 * @param user_id
	 * @return
	 */
	@SuppressWarnings("unchecked")
	public List<UserDevice> getByUserid(long user_id) {
		String hql = " from UserDevice where user_id = :user_id ";
		List<UserDevice> devices = (List<UserDevice>) dataDao.getObjectsViaParam(hql, new String[] { "user_id" },
				user_id);
		return devices;
	}

}
